﻿using FunctionalCLR.Core;
using FunctionalCLR.Shell;

namespace Zove.Shell.Core {
    /// <summary>
    /// the parser factory
    /// </summary>
    public class ZoveShellParserFactory : AbstractParserFactory {

        private IContext context = null;

        /// <summary>
        /// Default constructor
        /// </summary>
        /// <param name="context"></param>
        public ZoveShellParserFactory(
            IContext context)
            : base() {
            this.context = context;
        }

        /// <summary>
        /// Create a parser
        /// </summary>
        /// <param name="expr"></param>
        /// <returns></returns>
        public override Parser CreateParser(string expr) {
            ContextParser cp = new ContextParser(expr, context);
            cp.ConstantManager
                = DefaultDependencyManager.Instance.ConstantManager;
            cp.FunctionManager
                = context.GetFunctionManager();
            cp.ParserFactory
                = this;
            cp.Context = this.context;

            return cp;
        }

        /// <summary>
        /// Create a parser
        /// </summary>
        /// <param name="expr"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public override Parser CreateParser(string expr, object context) {
            return this.CreateParser(expr);
        }
    }
}
